﻿@{
    ViewBag.Title = "MenuTree";
}
@using Sunboxsoft.Bases.Web

<ul class="nav nav-list">
    @foreach (var lv1Menu in ViewBag.Menus)
    {
        if (lv1Menu.IsActived)
        {
            <li class="active">
                <a href="#">
                    <i class="@lv1Menu.Icon"></i>
                    <span class="menu-text">@lv1Menu.Text</span>
                </a>
            </li>
        }
        else if (lv1Menu.IsFolder)
        {
            <li @{string lv1Class = lv1Menu.IsOpened ? "class='open'" : ""; @Html.Raw(@lv1Class) }>
                <a href="#" class="dropdown-toggle">
                    <i class="@lv1Menu.Icon"></i>
                    <span class="menu-text">@lv1Menu.Text</span>
                    <b class="arrow icon-angle-down"></b>
                </a>
                <ul class="submenu" @{string lv1Style = lv1Menu.IsOpened ? "style='display: block;'" : ""; @Html.Raw(lv1Style) }>
                    @foreach (var lv2Menu in lv1Menu.Children)
                    {
                        if (lv2Menu.IsActived)
                        {
                            <li class="active">
                                <a href="#">
                                    <i class="@lv2Menu.Icon"></i>
                                    <span class="menu-text">@lv2Menu.Text</span>
                                </a>
                            </li>
                        }
                        else if (lv2Menu.IsFolder)
                        {
                            <li @{string lv2Class = lv2Menu.IsOpened ? "class='open'" : ""; @Html.Raw(@lv2Class)}>
                                <a href="#" class="dropdown-toggle">
                                    <i class="@lv2Menu.Icon"></i>
                                    <span class="menu-text">@lv2Menu.Text</span>
                                    <b class="arrow icon-angle-down"></b>
                                </a>
                                <ul class="submenu" @{string lv2Style = lv2Menu.IsOpened ? "style='display: block;'" : ""; @Html.Raw(lv2Style)}>
                                    @foreach (var lv3Menu in lv2Menu.Children)
                                    {
                                        if (lv3Menu.IsActived)
                                        {
                                            <li class="active">
                                                <a href="#">
                                                    <i class="@lv3Menu.Icon"></i>
                                                    <span class="menu-text">@lv3Menu.Text</span>
                                                </a>
                                            </li>
                                        }
                                        else if (lv3Menu.IsFolder)
                                        {
                                            <li @{string lv3Class = lv3Menu.IsOpened ? "class='open'" : ""; @lv3Class     }>
                                                <a href="#" class="dropdown-toggle">
                                                    <i class="@lv3Menu.Icon"></i>
                                                    <span class="menu-text">@lv3Menu.Text</span>
                                                    <b class="arrow icon-angle-down"></b>
                                                </a>
                                            </li>
                                        }
                                        else
                                        {
                                            <li>
                                                <a href="@lv3Menu.LinkUrl">
                                                    <i class="@lv3Menu.Icon"></i>
                                                    <span class="menu-text">@lv3Menu.Text</span>
                                                </a>
                                            </li>
                                        }
                                    }
                                </ul>
                            </li>
                        }
                        else
                        {
                            <li>
                                <a href="@lv2Menu.LinkUrl">
                                    <i class="@lv2Menu.Icon"></i>
                                    <span class="menu-text">@lv2Menu.Text</span>
                                </a>
                            </li>
                        }
                    }
                </ul>
            </li>
        }
        else
        {
            <li>
                <a href="@lv1Menu.LinkUrl">
                    <i class="@lv1Menu.Icon"></i>
                    <span class="menu-text">@lv1Menu.Text</span>
                </a>
            </li>
        }
    }
</ul>
